//! # 高级构建器模块测试
//! 
//! 本模块包含对高级构建器功能的测试用例。

#[cfg(test)]
mod tests {
    use super::*;
    use crate::advanced_builder::core::AdvancedRustCloudBuilder;
    use crate::advanced_builder::validators::BasicConfigValidator;
    use crate::advanced_builder::plugins::DatabasePlugin;

    #[tokio::test]
    async fn test_advanced_builder() {
        let framework = AdvancedRustCloudBuilder::new("test-service")
            .for_development()
            .enable_metrics()
            .enable_tracing()
            .use_plugin(Box::new(DatabasePlugin::new("postgresql://localhost:5432/test".to_string())))
            .add_validator(Box::new(BasicConfigValidator))
            .build()
            .await
            .unwrap();

        assert_eq!(framework.get_config().service.name, "test-service");
        assert_eq!(framework.get_config().service.environment, "development");
        assert!(framework.get_config().monitoring.metrics.enabled);
    }

    #[tokio::test]
    async fn test_conditional_configuration() {
        let is_production = false;
        
        let builder = AdvancedRustCloudBuilder::new("test-service")
            .when(is_production, |b| b.for_production())
            .when(!is_production, |b| b.for_development());

        assert_eq!(builder.config.service.environment, "development");
    }

    #[tokio::test]
    async fn test_plugin_system() {
        let builder = AdvancedRustCloudBuilder::new("test-service")
            .use_plugin(Box::new(DatabasePlugin::new("postgresql://localhost:5432/test".to_string())));

        assert_eq!(builder.plugins.len(), 1);
        assert_eq!(builder.plugins[0].name(), "database");
    }

    #[tokio::test]
    async fn test_config_validator() {
        let validator = BasicConfigValidator;
        let config = crate::config::RustCloudConfig::default();
        
        // 这应该会失败，因为默认配置的服务名称是空的
        let result = validator.validate(&config).await;
        assert!(result.is_err());
    }
}